﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class doctor_message : System.Web.UI.Page
{
    protected Doctor doc;
    protected int Guid;
    protected Message mes;
    protected void Page_Load(object sender, EventArgs e)
    {
        doc = Doctor.Check();
        if (doc == null)
        {
            Session.Add(Params.SystemError, "请先登录");
            Response.Redirect(Params.RootHttp + "default.aspx");
        }
        this.Guid = Convert.ToInt32(Request.Params["guid"]);
        this.mes = new Message(this.Guid);
        if (!Page.IsPostBack)
        {
            this.MyDataBind();
        }
    }

    public void MyDataBind()
    {

        this.Title = this.doc.RealName+"-读信件-" + this.mes.Title;
        this.conNav.Title = "读信件";
        this.conRecvers.UserGuid = this.doc.Guid;
        this.labTitle.Text = mes.Title;
        this.labTime.Text = mes.CreateTime.ToString();
        this.divBody.InnerHtml = mes.Body.Replace("\n", "<br />").Replace(" ", Params.SPACE);
        if (mes.Attachment != "")
        {
            this.hlAttachment.Visible = true;
            this.hlAttachment.NavigateUrl = Params.FilesFolderHttp + mes.Attachment;
        }
        if (this.doc.Guid == mes.FromGuid)
        {
            this.labSenderName.Visible = false;
            this.conRecvers.UserGuid = this.doc.Guid;
            this.conRecvers.RecversStr = mes.ToGuidsStr;
            this.btnReply.Visible = false;
        }
        else
        {
            this.conRecvers.Visible = false;
            this.labSenderName.Text = "发件人：" + Message.GetSenderName(mes.Guid, this.doc.Guid);
            if (!mes.ReadYeat(this.doc.Guid))
            {
                Relationship.Update(this.doc.Guid, Message.StrRecv, mes.Guid, Message.StrRead);
            }
        }
    }
    protected void btnReply_Click(object sender, EventArgs e)
    {
        Response.Redirect("write.aspx?recvers=" + this.mes.FromGuid.ToString()+"&uid="+Request.Params["uid"]);
    }
}
